package com.study.dao;

import com.study.entity.SysUserEntity;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class SysUserDao  {

    private static List<SysUserEntity> userList = new ArrayList<>();

    static{
        userList.add(new SysUserEntity(1L,"tom","123456","sys:read"));
        userList.add(new SysUserEntity(2L,"jam","123456","sys:delete"));
        userList.add(new SysUserEntity(3L,"admin","admin","sys:delete,sys:read"));
    }

    //@Select("select * from sys_user where username = #{username}")
    public SysUserEntity selectOne(String userName){
        for(SysUserEntity entity : userList){
            if(entity.getUsername().equals(userName)){
                return entity;
            }
        }
        return null;
    }

    //@Select("select permission from sys_user where user_id = #{userId}")
    public String queryAllPerms(Long userId){
        for(SysUserEntity entity : userList){
            if(entity.getUserId().longValue() == userId.longValue()){
                return entity.getPermission();
            }
        }
        return null;
    }
}
